<?include "settings.tbh"?>
<?include "global.tbh"?>
<?include "html_common.tbh"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?if NOT verifySession() then
	setsend("Brak dostepu")
	goto finish
end if?>
<head>
  <meta http-equiv="Content-Type"
 content="text/html; charset=utf-8"/>
  <title>Nastawy temperatur</title>

  <style type="text/css"/>

<?
  Dim x As Byte
  Dim s As String
  romfile.open("style.css")
  Do
     x=sock.txfree
     s=romfile.getdata(x)
     sock.setdata(s)
     sock.send
  Loop While Len(s)=x
?>

  </style>
  <script>
  var maxHeatingTemp=<?sock.setdata(getSensorValue("ogrMax"))?>, maxCwuTemp=<?sock.setdata(getSensorValue("cwuMax"))?>,
  minHeatingTemp=<?sock.setdata(getSensorValue("ogrMin"))?>, minCwuTemp=<?sock.setdata(getSensorValue("cwuMin"))?>
  minBapTemp=<?sock.setdata(getSensorValue("bapMin"))?>, maxBapTemp=<?sock.setdata(getSensorValue("bapMax"))?>,
  minBawTemp=<?sock.setdata(getSensorValue("bawMin"))?>, maxBawTemp=<?sock.setdata(getSensorValue("bawMax"))?>,
  minJacTemp=<?sock.setdata(getSensorValue("jacMin"))?>, maxJacTemp=<?sock.setdata(getSensorValue("jacMax"))?>;
  function displayDialog(option)
  {
  var min,max;
  if (option=="ogrSet") {min=minHeatingTemp; max=maxHeatingTemp;}
  if (option=="cwuSet") {min=minCwuTemp; max=maxCwuTemp;}
  if (option=="bapSet") {min=minBapTemp; max=maxBapTemp;}
  if (option=="bawSet") {min=minBawTemp; max=maxBawTemp;}
  if (option=="jacSet") {min=minJacTemp; max=maxJacTemp;}
  
	var txt = document.getElementById(option).childNodes[0].nodeValue;
	txt = txt.substr(0,txt.length-2);
	var temperature=displayTemperaturePrompt(min,max,txt);
	if (temperature!=null){
	var request=new XMLHttpRequest();
	request.open("GET","setValue.html?sensor="+option+"&value="+temperature*10,false);
	request.send();
	var tmp=document.getElementById(option).childNodes[0];
	tmp.nodeValue = temperature+"°C";
	}
	
};
function displayTemperaturePrompt(min,max,text)
{
	var input, correct=false;
	var patt=new RegExp("^[0-9]+\.?[0-9]?$");
	do {
		input = prompt("Zadana temperatura:",text);
		if (input==null) return null;
		if (patt.test(input)){
			if (input<min ||input>max){
				alert("Temperatura musi być w zakresie od "+min+" do "+max);
			}
			else{correct=true;}
		}
		else
		{
			alert("Zły format liczby"+input);
		}
			
	}while(!correct);
	return input;
}
  </script>
  
</head>
<body>
<?include "settings.tbh"?>
<div class="wrapper">
<div class="top-sh1"></div>
<div class="banner-area">
<div class="banner-sh" style="background:url(left-sh-1.png) no-repeat right top"></div>
<div class="banner-bg1">
<div class="banner-txt">
<div class="banner-txt-left">
Panel zarządzania
</div>
</div>
<div class="nav-area">
<ul class="navigation">
 <li><a href="wizualizacja.html?sid=<?setsend(getSessionID())?>">Wizualizacja</a></li>
  <li><a href="nastawy.html?sid=<?setsend(getSessionID())?>">Nastawy temperatur</a></li>
  <li><a href="settings.html?sid=<?setsend(getSessionID())?>">Ustawienia</a></li>
  <li><a href="#">Pomoc</a></li>
</ul>
</div>
<div class="nav-sh"></div>
</div>
<div class="banner-sh" style="background:url(right-sh-1.png) no-repeat left top"></div>
</div>
<div class="warpper-mid">
<div class="mid-left">
<h2 style="padding: 20px 0px 5px 30px;">Regulacja temperatury</h2>
<table rules="none" style="margin: 10px 0px 0px 50px; border:1px solid green;">
<tr> 
<td><b>Nazwa</b></td><td><b>Temperatura aktualna</b></td><td><b>Temperatura zadana</b></td>
</tr>

<tr>
<td><b>Temperatura Powietrza</b></td><td><?sock.setdata(getSensorValue("ogrCur"))?>°C</td><td id="ogrSet"><?sock.setdata(getSensorValue("ogrSet"))?>°C</td><td><button type="button" onclick="displayDialog('ogrSet')">Zmiana</button></td>
</tr>
<tr>
<td><b>Ciepła woda użytkowa</b></td><td><?sock.setdata(getSensorValue("cwuCur"))?>°C</td><td id="cwuSet"><?sock.setdata(getSensorValue("cwuSet"))?>°C</td><td><button type="button" onclick="displayDialog('cwuSet')">Zmiana</button></td>
</tr>

<?if hasSwimmingPool() =true then
setsend("<tr><td><b>Basen - woda</b></td><td>"+getSensorValue("bawCur")+"C</td><td td id=\x22bawSet\x22>"+getSensorValue("bawSet")+"°C</td><td><button type=\x22button\x22 onclick=\x22displayDialog('bawSet')\x22>Zmiana</button></td></tr>")
setsend("<tr><td><b>Basen - powietrze</b></td><td>"+getSensorValue("bapCur")+"°C</td><td id=\x22bapSet\x22>"+getSensorValue("bapSet")+"°C</td><td><button type=\x22button\x22 onclick=\x22displayDialog('bapSet')\x22>Zmiana</button></td></tr>")
end if
?>

<?if hasJacuzzi() = true then
setsend("<tr><td><b>Jacuzzi</b></td><td>"+getSensorValue("jacCur")+"°C</td><td id=\x22jacSet\x22>"+getSensorValue("jacSet")+"°C</td><td><button type=\x22button\x22 onclick=\x22displayDialog('jacSet')\x22>Zmiana</button></td></tr>")
end if
?>
</table>


</div>

<div class="warpper-bot">
<div class="footer-right">


<p class="footer-txt">jakas stopka</p>
</div>
</div>
</div>
</div>
</body>
<?finish:?>
</html>
